package cn.edu.wfit.modules.directionmanagement.controller;

import java.util.List;

import cn.edu.wfit.modules.directionmanagement.domain.WfitDirection;
import cn.edu.wfit.modules.directionmanagement.service.IWfitDirectionService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;

import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 方向Controller
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/direction")
public class WfitDirectionController extends BaseController
{
    @Autowired
    private IWfitDirectionService wfitDirectionService;

    /**
     * 查询方向列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WfitDirection wfitDirection)
    {
        startPage();
        List<WfitDirection> list = wfitDirectionService.selectWfitDirectionList(wfitDirection);
        return getDataTable(list);
    }

    /**
     * 导出方向列表
     */
    @RequiresPermissions("system:direction:export")
    @Log(title = "方向", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitDirection wfitDirection)
    {
        List<WfitDirection> list = wfitDirectionService.selectWfitDirectionList(wfitDirection);
        ExcelUtil<WfitDirection> util = new ExcelUtil<WfitDirection>(WfitDirection.class);
        util.exportExcel(response, list, "方向数据");
    }

    /**
     * 获取方向详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wfitDirectionService.selectWfitDirectionById(id));
    }

    /**
     * 新增方向
     */
    @RequiresPermissions("system:direction:add")
    @Log(title = "方向", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitDirection wfitDirection)
    {
        return toAjax(wfitDirectionService.insertWfitDirection(wfitDirection));
    }

    /**
     * 修改方向
     */
    @RequiresPermissions("system:direction:edit")
    @Log(title = "方向", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitDirection wfitDirection)
    {
        return toAjax(wfitDirectionService.updateWfitDirection(wfitDirection));
    }

    /**
     * 删除方向
     */
    @RequiresPermissions("system:direction:remove")
    @Log(title = "方向", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wfitDirectionService.deleteWfitDirectionByIds(ids));
    }
}
